package calendario_teste;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.ScrollPane;

import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

import java.awt.GridBagLayout;
import javax.swing.JTabbedPane;
import java.awt.GridBagConstraints;

public class JanelaCalendario extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel panelTabs = null;
	private JTabbedPane tabbedPane = null;
	
	private JComponent panelMes = null;
	private JComponent panelSemana = null;
	private JComponent panelDia = null;
	
	private MonthCanvas canvas1;
	private DayCanvas dayCanvas;// = new DayCanvas();
	Dimension d = new Dimension(140*7, 90*5);
	 
	private String stringTabMes = "Mes"; 
	private String stringTabSemana = "Semana"; 
	private String stringTabDia = "Dia"; 
	private String stringDia = "Friday 11/03";
	/**
	 * This is the default constructor
	 */
	public JanelaCalendario() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize((140*7)+25, (90*5)+44);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
		this.setResizable(false);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getPanelTabs(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes panelTabs	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getPanelTabs() {
		if (panelTabs == null) {
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.BOTH;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.weighty = 1.0;
			gridBagConstraints.anchor = GridBagConstraints.EAST;
			gridBagConstraints.gridx = 0;
			panelTabs = new JPanel();
			panelTabs.setLayout(new GridBagLayout());
			panelTabs.add(getTabbedPane(), gridBagConstraints);
		}
		return panelTabs;
	}
	
	//Creates tabs content
	protected JComponent makePanelSemana() {
        JPanel panel = new JPanel(false);
        JPanel panel1 = new JPanel(false);
        JScrollPane diaScrollPane;
        WeekCanvas weekCanvas;// = new WeekCanvas();
        
        panel1.setLayout(new GridLayout(1, 7));
        for(int i=0;i<7;i++){
        	weekCanvas = (WeekCanvas) makeDayWeekCanvas();
        	weekCanvas.setDay("Day: "+ (i+1));
        	panel1.add(weekCanvas.getPanelDay());
        }
        diaScrollPane=new JScrollPane(panel1);
       // diaScrollPane.setSize(new Dimension(140,800));
       // panel.setLayout(new BorderLayout());
       // panel.add(diaScrollPane, BorderLayout.CENTER);
      // panel.setPreferredSize(d);
        return panel1;
    }
	
	//cria o painel do dia, com scroll
	protected JComponent makePanelDia() {
        JPanel panel = new JPanel(false);
        JScrollPane diaScrollPane;
		dayCanvas = new DayCanvas();
		JPanel panel1 = new JPanel();
		
		//diaScrollPane = new JScrollPane(dayCanvas);
		
		panel.setLayout(new BorderLayout());	
		
		//panel.add(diaScrollPane, BorderLayout.CENTER);
		
        panel1=(JPanel) dayCanvas.getPanelDay();
        diaScrollPane=new JScrollPane(panel1);
        
        panel.add(diaScrollPane, BorderLayout.CENTER);
        panel.setPreferredSize(d);
        return panel;
    }
	
	
	protected JComponent makePanelMes() {
        JPanel panel = new JPanel(false);
		JPanel panelMeses = new JPanel();
		TopCanvas topCanvasMes = new TopCanvas();
		// cria cada quadradinho do dia, no painel do Mes
		panelMeses.setLayout(new GridLayout(5, 7));
		for(int i=1; i<32; i++){
			panelMeses.add(makeDayMonthCanvas(i));
		}	
		panel.setLayout(new BorderLayout());
		panel.add(panelMeses, BorderLayout.CENTER);
		panel.add(topCanvasMes, BorderLayout.NORTH);
		   
        //panel.setLayout(new GridLayout(5, 7));
        panel.setPreferredSize(d);
        return panel;
    }
	
	
	

	/**
	 * This method initializes tabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getTabbedPane() {
		if (tabbedPane == null) {
			tabbedPane = new JTabbedPane();
			

			panelMes = makePanelMes();
			panelDia = makePanelDia();
			panelSemana = makePanelSemana();
			
			
			
			
			//insere os paineis nos tabs.
			tabbedPane.addTab(stringTabMes,null,panelMes,"Vista Mes do Calendario");
			tabbedPane.addTab(stringTabDia,null,panelDia,"Vista Dia do Calendario");
			tabbedPane.addTab(stringTabSemana,null,panelSemana,"Vista Semana do Calendario");
			
		}
		return tabbedPane;
	}

	private Canvas makeDayMonthCanvas(int day){
		return new MonthCanvas(day);
	}
	private Canvas makeDayWeekCanvas(){
		return new WeekCanvas();
	}
	
}
